<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
 <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="css/style.css"/>       
        <link rel="stylesheet" href="assets/css/ace.min.css" />
        <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
        <link href="Widget/icheck/icheck.css" rel="stylesheet" type="text/css" />
		<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
	    <script src="js/jquery-1.9.1.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
<title>添加产品分类</title>
</head>
<body>
<div class="type_style">
 <div class="type_title">产品类型信息</div>
  <div class="type_content">
  <div class="Operate_btn">
  <a href="javascript:void(0)" class="btn  btn-warning" id="add"><i class="icon-edit align-top bigger-125"></i>新增子类型</a>
  <a href="javascript:void(0)" class="btn  btn-success" id="update"><i class="icon-ok align-top bigger-125"></i>修改该类型</a>
  <a href="javascript:void(0)" class="btn  btn-danger" id="delete"><i class="icon-trash   align-top bigger-125"></i>删除该类型</a>
  </div>
  <form action="" method="post" class="form form-horizontal" id="form-user-add" style="display:none">
    <div class="Operate_cont clearfix" id="zilei0">
      <label class="form-label"><span class="c-red">*</span>当前分类：</label>
      <div class="formControls ">
        <input type="text" class="input-text" value="" placeholder="" id="name" name="name">
      </div>
    </div>
        <div class="Operate_cont clearfix" id="zilei">
      <label class="form-label"><span class="c-red">*</span>子类名称：</label>
      <div class="formControls ">
        <input type="text" class="input-text" value="" placeholder="" id="childName" name="childName">
      </div>
    </div>
        <div class="Operate_cont clearfix" id="zilei1">
      <label class="form-label"><span class="c-red">*</span>排序：</label>
      <div class="formControls ">
        <input type="text" class="input-text" value="" placeholder="" id="orderId" name="orderId">
      </div>
    </div>
    <div class="Operate_cont clearfix" id="zilei2">
    <label class="form-label">备注：</label>
    <div class="formControls">
    <textarea id="remark" name="remark" rows="" class="textarea remark"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,100)"></textarea>
     <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
    </div>
    </div>
       <div class="sub deleteSub" style="display:none">
     <div class="" style=" text-align:center">
      <input class="btn btn-primary radius" type="submit" value="提交删除">
      </div>
    </div>
           <div class="sub updateSub" style="display:none">
     <div class="" style=" text-align:center">
      <input class="btn btn-primary radius" type="submit" value="提交修改">
      </div>
    </div>
           <div class="sub insertSub" style="display:none">
     <div class="" style=" text-align:center">
      <input class="btn btn-primary radius" type="submit" value="提交添加">
      </div>
    </div>
  </form>
  </div>
</div> 
</div>
<script type="text/javascript" src="Widget/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="Widget/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="assets/layer/layer.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script type="text/javascript">
function insert(){
	var inserto=function(result){
		if(result.state==1){
			alert("新增类型成功");
			window.parent.loadZtree();
			$("#form-user-add").data("treeNode","");
			$("#form-user-add input#name").val("");
			$("#form-user-add input#orderId").val("");
			$("#form-user-add #remark").val("");
			$("#form-user-add input#childName").val("");
		}
		else alert(result.message);
	}
	return inserto;
}
function deleted(){
	var myDelete=function(result){
		if(result.state==1){
			alert("删除类型成功");
			window.parent.loadZtree();
			$("#form-user-add").data("treeNode","");
			$("#form-user-add input#name").val("");
			$("#form-user-add input#orderId").val("");
			$("#form-user-add #remark").val("");
			$("#form-user-add input#childName").val("");
		}
		else alert(result.message);
	}
	return myDelete;
}
function myUpdate(){
	var innerUpdate=function(result){
		if(result.state==1){
			alert("更改类型成功");
			window.parent.loadZtree();
			$("#form-user-add").data("treeNode","");
			$("#form-user-add input#name").val("");
			$("#form-user-add input#orderId").val("");
			$("#form-user-add #remark").val("");
			$("#form-user-add input#childName").val("");
		}
		else alert(result.message);
	}
	return innerUpdate;
}
function update(){
	$(".sub input").off("click");
	   if($(this).attr("id")=="add"){
		   $("#form-user-add").css("display","block");
		   $(".sub.insertSub").css("display","block");
		   $(".sub.updateSub").css("display","none");
		   $(".sub.deleteSub").css("display","none");
		   $("#form-user-add #zilei0").css("display","block");
		   $("#form-user-add #zilei").css("display","block");
		   $("#form-user-add #zilei1").css("display","block");
		   $("#form-user-add #zilei2").css("display","block");
		   $(".sub.insertSub input").click(function(){
			   var name=$("input#childName").val();
			   if(name==""){
				   alert("分类名不能为空")
				   return
			   }
			   url="/product/productType/insertObjects"
			   var orderId=$("input#orderId").val();
			   var remark=$("input#remark").val();
			   var params;
			   if(!$("#form-user-add").data("treeNode")){
				   params={name:name,orderId:orderId,remark:remark}
			   }
			   else{
				   var parentId=$("#form-user-add").data("treeNode").id;
				   params={name:name,orderId:orderId,remark:remark,parentId:parentId};
			   }
			   $.post(url,params,insert());
		   })
	   }
	   if($(this).attr("id")=="update"){
		   $("#form-user-add").css("display","block");
		   $(".sub.insertSub").css("display","none");
		   $(".sub.updateSub").css("display","block");
		   $(".sub.deleteSub").css("display","none");
		   $("#form-user-add #zilei0").css("display","block");
		   $("#form-user-add #zilei").css("display","none");
		   $("#form-user-add #zilei1").css("display","block");
		   $("#form-user-add #zilei2").css("display","block");
		   $(".sub.updateSub input").click(function(){
			   var name=$("input#name").val();
			   if(name==""){
				   alert("分类名不能为空")
				   return
			   }
			   var url="/product/productType/updateObject";
			   var orderId=$("input#orderId").val();
			   var remark=$("input#remark").val();
			   var id=$("#form-user-add").data("treeNode").id;
			   if(!id){
				   alert("请先选择")
				   return
			   }
			   var params={name:name,id:id,orderId:orderId,remark:remark};
			   $.post(url,params,myUpdate());
		   });
	   }
	   if($(this).attr("id")=="delete"){
		   $("#form-user-add").css("display","block");
		   $(".sub.insertSub").css("display","none");
		   $(".sub.updateSub").css("display","none");
		   $(".sub.deleteSub").css("display","block");
		   $("#form-user-add #zilei0").css("display","block");
		   $("#form-user-add #zilei").css("display","none");
		   $("#form-user-add #zilei1").css("display","none");
		   $("#form-user-add #zilei2").css("display","none");
		   $(".sub.deleteSub input").click(function(){
			   var name=$("input#childName").val();
			   if(!$("#form-user-add").data("treeNode")){
				   alert("请先选择")
				   return
			   }
			   var id=$("#form-user-add").data("treeNode").id;
			   url="/product/productType/deleteObject"
			   var params={id:id};
			   $.post(url,params,deleted());
		   })
	   }
}
$(function(){
	$(".Operate_btn").on("click",".btn",update);
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-user-add").Validform({
		tiptype:2,
		callback:function(form){
			form[0].submit();
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});
</script>
</body>
</html>